<template>
  <div>
    <div class="h60">
      <span class="exnum">{{ Num }}.{{ item.title }}</span>
      <span class="labels">
        <span v-if="item.isJt == '1'">机经</span>
        <span v-if="item.isJt !== '1'" style="background: #7cc3d6">练习题</span>
        <span
          style="background: #ff5e4e"
          v-if="item.labelStyle == 'wrong-color'"
          >错题</span
        >
        <span style="background: #13bfbf" v-if="item.isYc == '1'"
          >本周预测</span
        >
       
        <span style="background: #94d0f7">{{ item.titleNumber }}</span>
      </span>
    </div>

    <div class="h107">
      {{ item.content }}
    </div>
    <div class="time">
      <span>剩余时间：{{ s_to_hs(answerTime) }}</span>
    </div>

    <div class="myanswer">
      <div class="bt">我的答案</div>
      <div class="insert">
        <div class="bg">
          <textarea
            @input="descInput"
            v-model="answer"
            placeholder="输入你的回答"
            class="txt"
          ></textarea>
        </div>
        <span>单词数：{{ countNum }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import writingUtil from "@/utils/writingUtil";
export default {
  props: ['item', 'Num'],
  mixins: [writingUtil],
  data () {
    return {
      answerTime: 1200,//答题时间
      countNum: 0,
      answer: ''
    }
  },
  created () {
    if (this.answerTime > 0) {
      setInterval(() => {
        if(this.answerTime>0){
          this.answerTime--
        }
      }, 1000);
    }

    this.answer=this.item.answer
  },
  methods: {
    // 输入字数
    descInput () {
       this.$emit('sendAnswer',this.answer)
      if (this.answer.split(' ').length > 200) {
        this.answer = this.answer.slice(0, 200)
        this.$msg.error("字数不能超过200")
      }
      this.countNum = this.answer.split(' ').length
    }
  },
}
</script>

<style lang="less" scoped>
.myanswer {
  height: 25.5rem;
  background-color: #fff;
  // padding: 0 2.5rem;
  box-sizing: border-box;
  position: relative;
  .bt {
    height: 6.25rem;
    line-height: 6.25rem;
    font-size: 2rem;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #333333;
  }
  .txt {
    height: 13.125rem;
    background-color: #f7f7f7;
    border: none;
    outline: none;
    padding: 1.5rem;
    box-sizing: border-box;
    font-size: 1.125rem;
    color: #999999;
    resize: none;
    width: 100%;
  }
  .insert {
    border-radius: 0.3125rem;
    overflow: hidden;
    .bg {
      height: 17.3125rem;
      box-sizing: border-box;
      background-color: #f7f7f7;
    }
    span {
      font-size: 1.125rem;
      color: #999;
      position: absolute;
      right: 2.3125rem;
      bottom: 3.4375rem;
    }
  }
}
.h60 {
  height: 3.75rem;
  line-height: 3.75rem;
  padding-left: 1.25rem;
  box-sizing: border-box;
  background-color: #f7f7f7;
  display: flex;
  position: relative;
  margin-bottom: 1rem;
  .exnum {
    width: 45rem;
    font-size: 1rem;
    color: #666;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .labels {
    display: flex;
    justify-content: flex-end;
    width: 21.25rem;
    span {
      height: 1.875rem;
      line-height: 1.875rem;
      padding: 0 0.375rem;
      box-sizing: border-box;
      background-color: #ff9b4f;
      border-radius: 0.1875rem;
      margin: 0.9375rem 0.46875rem;
      color: #fff;
      box-sizing: border-box;
    }
  }
}

.h107 {
  margin: 3.125rem 0 1.5625rem;
  width: 100%;
  background: #fffafa;
  border: 1px dashed #ff5e4e;
  border-bottom: 1px dashed #ff5e4e !important;
  box-sizing: border-box;
  padding: 1.25rem 1.75rem 1.6875rem;
  box-sizing: border-box;
  font-size: 1.125rem;
  color: #666;
  line-height: 2rem;
}
.time {
  font-size: 1rem;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #333333;
  span {
    margin-right: 1.875rem;
  }
}
</style>